package com.alliance.shuwei.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alliance.shuwei.entity.ResourceProvider;
import com.alliance.shuwei.repository.ResourceProviderDao;

@Transactional
@Service
public class ProviderService {
	@Autowired
	private ResourceProviderDao providerDao;

	public List<ResourceProvider> getAllProvider() {
		List<ResourceProvider> providers = new ArrayList<ResourceProvider>();
		Iterator<ResourceProvider> iterator = providerDao.findAll().iterator();
		while (iterator.hasNext()) {
			providers.add(iterator.next());
		}
		return providers;
	}

	public ResourceProvider getProviderById(int id) {
		return providerDao.findOne(id);
	}

	public ResourceProvider createProvider(ResourceProvider provider) {
		return providerDao.save(provider);
	}
}
